// Home-made (or not), no guarantees ! ^^


document.addEvent('domready', function(){
  
  var myField = new goog.editor.Field("add_task_comment_editme");
  
  // Create and register all of the editing plugins you want to use.
  myField.registerPlugin(new goog.editor.plugins.BasicTextFormatter());
  myField.registerPlugin(new goog.editor.plugins.RemoveFormatting());
  myField.registerPlugin(new goog.editor.plugins.UndoRedo());
  myField.registerPlugin(new goog.editor.plugins.ListTabHandler());
  myField.registerPlugin(new goog.editor.plugins.SpacesTabHandler());
  myField.registerPlugin(new goog.editor.plugins.EnterHandler());
  myField.registerPlugin(new goog.editor.plugins.HeaderFormatter());
  myField.registerPlugin(new goog.editor.plugins.LoremIpsum('Write your comment here...'));


  // Specify the buttons to add to the toolbar, using built in default buttons.
  var buttons = [
    goog.editor.Command.BOLD,
    goog.editor.Command.ITALIC,
    goog.editor.Command.UNDERLINE,
//    goog.editor.Command.FONT_COLOR,
//    goog.editor.Command.BACKGROUND_COLOR,
//    goog.editor.Command.FONT_FACE,
//    goog.editor.Command.FONT_SIZE,
    goog.editor.Command.UNDO,
    goog.editor.Command.REDO,
    goog.editor.Command.UNORDERED_LIST,
    goog.editor.Command.ORDERED_LIST,
//    goog.editor.Command.INDENT,
//    goog.editor.Command.OUTDENT,
//    goog.editor.Command.JUSTIFY_LEFT,
//    goog.editor.Command.JUSTIFY_CENTER,
//    goog.editor.Command.JUSTIFY_RIGHT,
    goog.editor.Command.SUBSCRIPT,
    goog.editor.Command.SUPERSCRIPT,
    goog.editor.Command.STRIKE_THROUGH,
    goog.editor.Command.REMOVE_FORMAT
  ];
  var myToolbar = goog.ui.editor.DefaultToolbar.makeToolbar(buttons,
      goog.dom.$('add_task_comment_toolbar'));

  // Hook the toolbar into the field.
  var myToolbarController =
      new goog.ui.editor.ToolbarController(myField, myToolbar);

  myField.makeEditable();
  
////////////////////////////////////////////////////////////////////////////////
  // FORM COMMENT SUBMIT
  
  $('add_task_comment_submit').addEvent ('click', function(e){
    e.stop();
    var comment_HTML = myField.getCleanContents();
    $('add_task_comment_comment').setProperty ('value', comment_HTML);
    var myHTMLRequest = new Request.HTML({
      url:'/addconditioncomment.do',
      onComplete: function (elts, tree, html, js){
        if (html) alert (html);
        window.location.reload();
      }
    }).post($('add_task_comment'));
  });

  
});


